package com.ruoyi.web.controller.chargeback.controller;


import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.charge.vo.CommissionRecordVo;
import com.ruoyi.charge.bo.CommissionRecordQueryBo;
import com.ruoyi.charge.bo.CommissionRecordAddBo;
import com.ruoyi.charge.bo.CommissionRecordEditBo;
import com.ruoyi.charge.service.ICommissionRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 分佣记录Controller
 *
 * @author fanqie
 * @date 2021-10-28
 */
@Api(value = "分佣记录控制器", tags = {"后台分佣记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/back/commission_record")
public class BackCommissionRecordController extends BaseController {

    private final ICommissionRecordService iCommissionRecordService;

    /**
     * 查询分佣记录列表
     */
    @ApiOperation("查询分佣记录列表")
    @PreAuthorize("@ss.hasPermi('back:commission_record:list')")
    @GetMapping("/list")
    public TableDataInfo<CommissionRecordVo> list(CommissionRecordQueryBo bo) {
        startPage();
        List<CommissionRecordVo> list = iCommissionRecordService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出分佣记录列表
     */
    @ApiOperation("导出分佣记录列表")
    @PreAuthorize("@ss.hasPermi('back:commission_record:export')")
    @Log(title = "分佣记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<CommissionRecordVo> export(CommissionRecordQueryBo bo) {
        List<CommissionRecordVo> list = iCommissionRecordService.queryList(bo);
        ExcelUtil<CommissionRecordVo> util = new ExcelUtil<CommissionRecordVo>(CommissionRecordVo.class);
        return util.exportExcel(list, "分佣记录");
    }

    /**
     * 获取分佣记录详细信息
     */
    @ApiOperation("获取分佣记录详细信息")
    @PreAuthorize("@ss.hasPermi('back:commission_record:query')")
    @GetMapping("/{id}")
    public AjaxResult<CommissionRecordVo> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iCommissionRecordService.queryById(id));
    }

    /**
     * 新增分佣记录
     */
    @ApiOperation("新增分佣记录")
    @PreAuthorize("@ss.hasPermi('back:commission_record:add')")
    @Log(title = "分佣记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody CommissionRecordAddBo bo) {
        return toAjax(iCommissionRecordService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改分佣记录
     */
    @ApiOperation("修改分佣记录")
    @PreAuthorize("@ss.hasPermi('back:commission_record:edit')")
    @Log(title = "分佣记录", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody CommissionRecordEditBo bo) {
        return toAjax(iCommissionRecordService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除分佣记录
     */
    @ApiOperation("删除分佣记录")
    @PreAuthorize("@ss.hasPermi('back:commission_record:remove')")
    @Log(title = "分佣记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iCommissionRecordService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
